<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table id="table1" border="1" cellspacing="0" cellpadding="10px">
			<tr>
				<th></th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>家庭住址</th>
			</tr>
			<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>张三</td>
					<td class="boy">男</td>
					<td>20</td>
					<td>福建省</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>张三</td>
					<td class="boy">男</td>
					<td>20</td>
					<td>福建省</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>大三</td>
					<td class="girl">女</td>
					<td>20</td>
					<td>福建省</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>小三</td>
					<td class="girl">女</td>
					<td>20</td>
					<td>福建省</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>张飞</td>
					<td class="sex"> 男</td>
					<td>20</td>
					<td>福建省</td>
				</tr>
			
		</table>
		<input id="checkall" type="checkbox" name="" value="" onclick="doAction1();"/>全选
		<input id="checkal2" type="checkbox" name="" value="" onclick="doAction2();"/>全选男
		<input id="checkal3" type="checkbox" name="" value="" onclick="doAction3();"/>全选女
	</body>
	<script type="text/javascript">
	function doAction1(){
		var table1Obj = document.getElementById('table1');
		console.log(table1Obj)
		var input1 = table1Obj.getElementsByTagName('input');
		console.log(input1)
		var checkall1 = document.getElementById('checkall').checked
		console.log(checkall1)
		for (var i = 0; i < input1.length; i++) {
			input1[i].checked = checkall1;
		}
	}
	function doAction2(){
		var sex1 = document.getElementsByClassName('sex');
		// console.log(sex1[0].parentElement.getElementsByTagName('input'))
		var checkall2 = document.getElementById('checkal2').checked
		for (var i = 0; i < sex1.length; i++) {
			if (sex1[i].innerText == '男') {
				var table2Obj = document.getElementById('table1')
				var input2 = table2Obj.getElementsByTagName('input')
				
				input2[i].checked = checkall2
			}
		}
	}
	function doAction3(){
		var sex2 = document.getElementsByClassName('sex');
		var checkall3 = document.getElementById('checkal3').checked
		for (var i = 0; i < sex2.length; i++) {
			if (sex2[i].innerText == '女') {
				var table3Obj = document.getElementById('table1')
				var input3 = table3Obj.getElementsByTagName('input')
				
				input3[i].checked = checkall3
			}
		}
	}
	</script>
</html>